import aiohttp
import json
from typing import AsyncGenerator

async def make_post_request(url: str, data: str) -> dict:
    """
    发送POST请求到指定URL
    
    Args:
        url (str): 目标URL
        data (str): JSON格式的请求数据
        
    Returns:
        dict: 响应数据
    """
    async with aiohttp.ClientSession() as session:
        async with session.post(url, data=data) as response:
            if response.status == 200:
                return await response.json()
            raise Exception(f"Request failed with status {response.status}")

async def make_stream_request(url: str, data: str) -> AsyncGenerator[dict, None]:
    """
    发送流式POST请求到指定URL
    
    Args:
        url (str): 目标URL
        data (str): JSON格式的请求数据
        
    Yields:
        dict: 响应数据片段
    """
    async with aiohttp.ClientSession() as session:
        async with session.post(url, data=data) as response:
            if response.status != 200:
                raise Exception(f"Request failed with status {response.status}")
                
            # 读取响应流
            async for line in response.content:
                if line:
                    try:
                        yield json.loads(line)
                    except json.JSONDecodeError:
                        continue
